{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑配置</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="edit_config" id="edit_config" >
                    <input type="hidden" name="id" value="{$info.id}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">配置标识：</label>
                            <div class="input-group col-sm-4">
                                <input id="name" type="text" class="form-control" name="name" value="{$info.name}">
                                <span class="help-block m-b-none"> 用于config函数调用，只能使用英文且不能重复</span>
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必填</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">配置标题：</label>
                            <div class="input-group col-sm-4">
                                <input id="title" type="text" class="form-control" name="title" value="{$info.title}">
                                <span class="help-block m-b-none"> 用于后台显示的配置标题</span>
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必填</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label yanse">配置类型：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="type" id="type">
                                    <option value="">==请选择==</option>
                                        {volist name="Think.config.config_type_list" id="type"} 
                                            <option value="{$key}" {eq name="$key" value="$info.type"}selected{/eq}>{$type}</option>
                                        {/volist}
                                </select>
                                <span class="help-block m-b-none typ"> （系统会根据不同类型解析配置值）</span>
                                <span class="help-block m-b-none typ"><i class="fa fa-info-circle"></i> 必填</span>
                                <a id="myEditors" style="color:#A94543"></a>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label gyanse">配置分组：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="group" id="group">
                                    <option value="">==请选择==</option>
                                        {volist name="Think.config.config_group_list" id="group"}
                                            <option value="{$key}" {eq name="$key" value="$info.group"}selected{/eq}
                                    >{$group}</option>
                                        {/volist}
                                </select>
                                <span class="help-block m-b-none gro"> （配置分组 用于批量设置 不分组则不会显示在系统设置中）</span>
                                <span class="help-block m-b-none gro"><i class="fa fa-info-circle"></i> 必填</span>
                                <a id="myGeditors" style="color:#A94543"></a>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">配置值：</label>
                            <div class="input-group col-sm-4">
                                <input id="value" type="text" class="form-control" name="value" value="{$info.value}">
                                <span class="help-block m-b-none"> 用于config函数调用显示的值</span>
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必填</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">配置项：</label>
                            <div class="input-group col-sm-4">
                                <textarea type="text" rows="5" name="extra" id="extra" class="form-control" >{$info.extra}</textarea>
                                <span class="help-block m-b-none"> 如果是枚举型 需要配置该项</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">配置描述：</label>
                            <div class="input-group col-sm-4">
                                <textarea type="text" rows="5" name="remark" id="remark" class="form-control" >{$info.remark}</textarea>
                                <span class="help-block m-b-none"> 配置详细说明</span>
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必填</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">排序：</label>
                            <div class="input-group col-sm-4">
                                <input id="sort" type="text" class="form-control" value="0" name="sort" value="{$info.sort}">
                                <span class="help-block m-b-none"> 用于显示的顺序</span>
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必填</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary btsave" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
    $(".btsave").click(function(){
        var type = $("#type").val();
        var group = $("#group").val();
        if(type==""){
            $('.yanse').css("color","#ED5666");
            $('#type_chosen').children().eq(0).css("border","1px solid #ED5666");
            $("#myEditors").css("display","");
            $("#myEditors").html("<i class='fa fa-times-circle'></i> 请选择配置类型");
        }else {
            $('.yanse').css("color","#686B6D");
            $("#myEditors").css("display", "none");
        }
        if(group == ""){
            $('.gyanse').css("color","#ED5666");
            $('#group_chosen').children().eq(0).css("border","1px solid #ED5666");
            $("#myGeditors").css("display","");
            $("#myGeditors").html("<i class='fa fa-times-circle'></i> 请选择配置分组");
        }else {
            $('.gyanse').css("color","#686B6D");
            $("#myGeditors").css("display", "none");
        }
    })
    $("#type").change(function(){
        $('.yanse').css("color","#686B6D");
        $('#type_chosen').children().eq(0).css("border","1px solid #CBD5DD");
        $("#myEditors").css("display", "none");
    })

    $("#group").change(function(){
        $('.gyanse').css("color", "#686B6D");
        $('#group_chosen').children().eq(0).css("border", "1px solid #CBD5DD");
        $("#myGeditors").css("display", "none");
    })

    $("#type").find("option[value='{$info.type}']").attr("selected", true);
    $("#group").find("option[value='{$info.group}']").attr("selected", true);

    $.validator.setDefaults({
        highlight: function(e) {
            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            $(e).closest(".form-control").css("color","#737373");
        },
        success: function(e) {
            // e.closest(".form-group").removeClass("has-error").addClass("has-success")
            $(e).closest(".form-group").removeClass("has-error");
        },
        errorElement: "span",
        errorPlacement: function(e, r) {
            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            if(r.is("#groupid")){
                e.appendTo(r.parent());
            }
        },
        errorClass: "help-block m-b-none",
        validClass: "help-block m-b-none"
    }), $().ready(function() {
        var e = "<i class='fa fa-times-circle'></i> ";
        jQuery.validator.addMethod("selectNoe", function(value, element) {
            var returnVal = true;
            var level = $("#type").val();
            if(level==""){
                returnVal = false;
            }
            return returnVal;
        }, e+"请选择配置类型");
        jQuery.validator.addMethod("selectNoe2", function(value, element) {
            var returnVal = true;
            var level = $("#group").val();
            if(level==""){
                returnVal = false;
            }
            return returnVal;
        }, e+"请选择配置分组");
        jQuery.validator.addMethod("extraNoe", function(value, element) {
            var returnVal = true;
            var level = $("#type").find("option:selected").text();
            var extra = $('#extra').val();
            if(level=="枚举" && extra==""){
                returnVal = false;
            }
            return returnVal;
        }, e+"枚举型此配置项必填");
        $("#edit_config").validate({
            rules: {
                name: {
                    required: !0,
                },
                value: {
                    required: !0,
                },
                type: {
                    required:!0,
                    selectNoe:true,
                },
                group:{
                    required:!0,
                    selectNoe2:true,
                },
                title:{
                    required:!0,
                },
                extra:{
                    extraNoe:true,
                },
                remark:{
                    required:!0,
                },
                sort:{
                    required:!0,
                    digits:true
                }

            },
            messages: {
                name: {
                    required: e + "请输入配置标识",
                },
                value: {
                    required: e + "请输入配置值",
                },
                title: {
                    required: e + "请输入配置标题",
                },
                remark: {
                    required: e + "请输入配置描述",
                },
                sort: {
                    required: e + "请输入排序值",
                    digits:e+"请输入整数"
                }
            },
            submitHandler: function(form) { //通过之后回调
//进行ajax传值
//                 var formData = new FormData($("#userAdd" )[0]);
                var type = $("#type").val();
                var group = $("#group").val();
                if(type==""){
                    $('.yanse').css("color","#ED5666");
                    $('#type_chosen').children().eq(0).css("border","1px solid #ED5666");
                    $("#myEditors").css("display","");
                    $("#myEditors").html("<i class='fa fa-times-circle'></i> 请选择配置类型");
                }else {
                    if (group == "") {
                        $('.gyanse').css("color", "#ED5666");
                        $('#group_chosen').children().eq(0).css("border", "1px solid #ED5666");
                        $("#myGeditors").css("display", "");
                        $("#myGeditors").html("<i class='fa fa-times-circle'></i> 请选择配置分组");
                    } else {
                        $('button').attr('disabled', 'disabled');
                        $.ajax({
                            url: "{:url('edit_config')}",
                            type: "post",
                            dataType: "json",
                            data: $("#edit_config").serialize(),
                            success: function (data) {
                                if (data.code == 200) {
                                    wk.success(data.msg,1,"{:url('config/index')}");
                                } else {
                                    $('button').removeAttr('disabled');
                                    wk.error(data.msg,2,'');
                                    return false;
                                }
                            }
                        });
                    }
                }
            },
        })
    });
</script>
</body>
</html>